<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>生活平台</title>
		<link rel="shortcut icon" href="../scripts/images/favicon.ico">
		<link rel="stylesheet" type="text/css"
			href="http://ump.deppon.com:8080/dpUMPPlatform-web/extjs4/resources/css/ext-all.css" />
		<style>
		#biaoti{
			font-weight:bold;
			text-align:center;
		}
		  *{font-size:13px!important;}
		.treeNodeIcon{background-image:url(${pageContext.request.contextPath}/scripts/images/treeNodeIcon.png) !important}
		.treeLeafIcon{background-image:url(${pageContext.request.contextPath}/scripts/images/treeLeafIcon.png) !important}
		.treeNodePackage{background-image:url(${pageContext.request.contextPath}/scripts/images/treeNodePackage.png) !important}
		.treeNodeLeaf{background-image:url(${pageContext.request.contextPath}/scripts/images/treeNodeLeafIcon.png) !important}
		.user{background-image:url(${pageContext.request.contextPath}/scripts/images/user.png) !important}
		.edit{background-image:url(${pageContext.request.contextPath}/scripts/images/edit.png) !important}
		.exit{background-image:url(${pageContext.request.contextPath}/scripts/images/exit.png) !important}
		.help{background-image:url(${pageContext.request.contextPath}/scripts/images/help.png) !important}
		.add{background-image:url(${pageContext.request.contextPath}/scripts/images/add.gif) !important}
		.del{background-image:url(${pageContext.request.contextPath}/scripts/images/delete.gif) !important}
		.logo{background-image:url(${pageContext.request.contextPath}/scripts/images/root5.gif) !important}
		.waitwork{background-image:url(${pageContext.request.contextPath}/scripts/images/waitwork.png) !important}
		</style>
		<script type="text/javascript" src="http://ump.deppon.com:8080/dpUMPPlatform-web/extjs4/bootstrap.js"></script>
		<script type="text/javascript" src="http://ump.deppon.com:8080/dpUMPPlatform-web/extjs4/locale/ext-lang-zh_CN.js"></script>
			
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/scripts/DBUtils.js"></script>
		<script>
		
		
		Ext.onReady(function(){
			//初始化提示条
	        Ext.QuickTips.init();
	    	var win;//修改密码window
	    	var statusText = Ext.create('Ext.toolbar.TextItem', {text: '生活平台 ©2012'});
	        var clock = Ext.create('Ext.toolbar.TextItem', {text: Ext.Date.format(new Date(), 'g:i:s A')});
			var indexTreeStore = Ext.create('Ext.data.TreeStore', {
				root : {
					expanded : true,	
					id:'0'
				},
				default:{expanded : true },
			proxy:{
				type:'ajax',
				url:'autorityManage/menuInfoAction.action',
				actionMethods:'POST',
				reader:{
					type:'json',
					root:'menus',	
				}
			 },
			  autoLoad:true
			});		
		    
			var treePanel = Ext.create('Ext.tree.TreePanel', {
				id: 'treepanel',
				store : indexTreeStore,
				region : 'west',
				collapsible : true,
				width : 177,
				border:false,
				split: true, 
				minWidth : 177,
				maxWidth : 177,
			    split: true,//可以合并
			    width:250,			    
				//动画效果
				animate:true,				
			    autoScroll: true,
				//树节点是否可见
		        rootVisible: false,
			  //使用vista风格的箭头图标，默认为false
			    useArrows: true,
			    collapseMode:'mini',
				listeners : {
					itemclick : function(node, record,item,index,e,eOpts){
					
						//点击菜单加载页面												
						   initTabpanel(record.raw.id,record.raw.text,record.raw.url);
				   			
					}
				}
			});
			
			var tabPanelTitle = Ext.create('Ext.tab.Panel', {
				region : 'center',
				id:'tabPanel',
				activeTab :0,
				items : [{
					title : '首页',
					id:'showIndex',
					html: '<iframe id="'+'showIndex'+'" src="'+'statiReport/showSendDetailReportIndex.action'+'" style="height:100%;width:100%;" frameborder="0"></iframe>'
				}]
			});
			
			/**
			*修改密码
			*/
				     
			     Ext.apply(Ext.form.VTypes, {
				//自定义验证两次输入的密码是否一致		
				    repetition: function(val, field) {     //返回true，则验证通过，否则验证失败
				        if (field.repetition) {               //如果表单有使用repetition配置，repetition配置是一个JSON对象，该对象提供了一个名为targetCmpId的字段，该字段指定了需要进行比较的另一个组件ID。
				             var cmp = Ext.getCmp(field.repetition.targetCmpId);   //通过targetCmpId的字段查找组件
				             if (Ext.isEmpty(cmp)) {      //如果组件（表单）不存在，提示错误
				                  Ext.MessageBox.show({
				                     title: '错误',
				                     msg: '发生异常错误，指定的组件未找到',
				                      icon: Ext.Msg.ERROR,
				                     buttons: Ext.Msg.OK
				                 });
				                return false;
				             }
				             if (val == cmp.getValue()) {  //取得目标组件（表单）的值，与宿主表单的值进行比较。
				                 return true;
				             } else {
				                return false;
				             }
				         }
				     },
				     repetitionText: '两次输入的密码不一致',
	         	});	
			
		//判断输入的密码是否正确
		var ress=0;
		function validOldPwd(){
			
			Ext.Ajax.request({ 
				url: 'autorityManage/validOldPassword.action', 
				params: { 
					
					'oldPassword' :Ext.getCmp('oldPassword').getValue()							
					}, 
					success: function(response) {
						var result = Ext.decode(response.responseText); 
						var returnMessage=result.resultMessage;
						ress=returnMessage.returnCode;	
						if(ress==5){
							 showInfoMsg("该用户已被删除",function(){
									Ext.Ajax.request({
										url : 'logoutAction.action',
										//退出成功
										success : function(response, opts) {
											window.location = 'index.action';
										},
										//退出失败
										exception : function(response, opts) {
											var result = Ext.decode(response.responseText);
											Ext.MessageBox.show({
								                title: login.i18n("退出失败"),
								                msg: result.message,
								                buttons: Ext.MessageBox.OK,
								                icon: Ext.MessageBox.ERROR
								            });
										}
									});
								}); 	
							
						}
						Ext.getCmp('oldPassword').isValid();
					} 									
				});		
			return ress;
		};
	   //修改密码
		function modifyPassword(form,params,successFn,failureFn){
			var url = 'autorityManage/updatePassword.action';
			//submitForm(url,form,params,successFn,failureFn);
			requestUmpAjax(url,params,successFn,failureFn);
		};

		
		 Ext.apply(Ext.form.VTypes, {
			 validOldPassword: function(val, field) {     //返回true，则验证通过，否则验证失败			     				
				var isTrueValue=ress;								
				if(isTrueValue==1){return true;}else{					
					return false;															
				}			 				   
			 },
		     validOldPasswordText: '输入的密码不正确'		
			});		
				 
			var modifyPwdForm=Ext.create('Ext.form.Panel',{
				id:'modifyPwdForm',
				layout : {
					type : 'table',	//table布局
					columns : 1	//列数
				},
				defaults: {//统一设置宽、居右
					margin:'10 10 10 40',//间距
					labelWidth:70,
					border:false,
					labelAlign: 'right',
					width : 215
				},
				defaultType:'textfield',//默认类型
				frame:true,
				height:45,
				region:'north',
				buttonAlign:'center',
				items:[{
					fieldLabel: '用户名',
					value:'${userNo}',
					readOnly:true,
					name:'userNo'
				},{
				
					fieldLabel: '旧密码',
					inputType:'Password',
					name:'oldPassword',
					id:'oldPassword',			      
					allowBlank: false,  
					blankText: '旧密码不能为空',
					vtype: 'validOldPassword',  //指定validOldPassword验证类型.
					listeners:{
						
						change:function(){
							/*
							*bug   2678 已修复
							*/
							validOldPwd();
						}
				}
				},{
					fieldLabel: '新密码',
					inputType:'password',
					id:'newPassword',
			        //通过正则表示式验证
					regex:/^[0-9]*$/,
		           //正则验证不通过的提示信息
					regexText:'密码只能是数字',
					allowBlank:false,//判断不能为空
					blankText:'新密码不能为空',//为空时自定义提示
					maxLength:20,
    				maxLengthText:'输入的密码不恩呢该超过20个字',//过长时自定义提示
					name:'rate.upLimit',	
					listeners:{
						blur:function(){
							Ext.getCmp('rePassword').isValid();
						}
				}
					
				},{
					fieldLabel: '密码确认',
					inputType:'password',
					id:'rePassword',
			        //通过正则表示式验证
					regex:/^[0-9]*$/,
		           //正则验证不通过的提示信息
					regexText:'密码只能是数字',
					allowBlank:false,//判断不能为空
					blankText:'确认密码不能为空',//为空时自定义提示
					maxLength:20,
    				maxLengthText:'输入的密码不能超过20个字',//过长时自定义提示
					name:'rate.rate',
				    vtype: 'repetition',  //指定repetition验证类型
					repetition: { targetCmpId : 'newPassword' }  //配置repetition验证，提供目标组件（表单）ID

				},{
					xtype:'hiddenfield',				
				}],
				buttons:[{
					xtype:'button',
					text:'保存',
					width:80,
					margin:'0 10 20 10',//间距
					handler:function(){
						if(modifyPwdForm.getForm().isValid()){
							if(Ext.getCmp('oldPassword').getValue()==Ext.getCmp('newPassword').getValue()){
								showInfoMsg("新密码与旧密码一致，无需修改！");
							}else{	
							var successFn = function(json){
						    	showInfoMsg("保存成功！");
						    	modifyPwdForm.getForm().reset();//重置		
						    	win.hide();
						    
						    };
						    var failureFn = function(json){
						    	showErrorMsg("保存失败！");
						    	modifyPwdForm.getForm().reset();//重置		
						    };
						    						 					
						    //调用方法
						modifyPassword(
								modifyPwdForm,
								{'newPassword' : Ext.getCmp('newPassword').getValue()},
								successFn,
					 			failureFn);
						 }
						}else{
							showInfoMsg("表单输入有误,请重新输入后保存！");
						}
					}
				},{
					xtype:'button',
					text:'关闭',
					width:80,
					handler:function(){						
						win.hide();
					}
				}]
			});
				
			if(!win){//需要定义全局变量,如果不存在就创建一个，保证只创建一次
				win=Ext.create('Ext.window.Window',{
					title:'修改密码',
					width:380,
					height:250,
					modal:true,//模式窗口（带蒙层，后面不可操作）
					layout:'fit',
					constrain  :true,    //约束视图显示
					closeAction:'hide',//关闭方式 （默认为销毁）
					items:[modifyPwdForm]
				});
			}
			
	    	var viewport = Ext.create('Ext.Viewport', {
	            layout: {
	                type: 'border',
	                padding: 5
	            },
	            items: [{ 
					id : 'banner',
					region : 'north',
					height:65,
					contentEl : 'div_img',
					//collapsible : true,
					//collapsed :false,
					hideBorders:true,
					border : false
				},{
	                region: 'center',
	                layout:'border',
					border:false,
					items:[treePanel,tabPanelTitle],
					tbar:new Ext.Toolbar({
						hideBorders:true,
						border:false,
					  	items :[
							{id:'logo',text:'',iconCls: 'logo'},    
					  		{id:'biaoti',xtype:'label',text:'德邦物流短信语音平台'},
							'->',
						    '当前用户',
						    {id:'user',text: '${userName}(${userNo})',iconCls: 'user'},//需要action里获取后改{id:'user',text:'${loginUser}',iconCls: 'user'}
						  //  '-','工号 :${userNo}', 
						  
						    '-','上次登录时间  ${lastLoginDate}','-',//同上
					  		{id:'edit',text:'修改密码',iconCls: 'edit',tooltip : '修改密码',handler:function(){
					  			modifyPwdForm.getForm().reset();//重置		
					  			win.show();
					  							
								
					  		}},
							'-',
					  		{id:'exit',text:'退出系统',iconCls: 'exit',tooltip : '退出系统',handler:function(){
					  			Ext.MessageBox.confirm('确认', '您确定要退出吗?',function(btn,text){
									if(btn=='yes'){
										//Ajax请求logout
										Ext.Ajax.request({
											url : 'logoutAction.action',
											//退出成功
											success : function(response, opts) {
												window.location = 'index.action';
											},
											//退出失败
											exception : function(response, opts) {
												var result = Ext.decode(response.responseText);
												Ext.MessageBox.show({
									                title: login.i18n("退出失败"),
									                msg: result.message,
									                buttons: Ext.MessageBox.OK,
									                icon: Ext.MessageBox.ERROR
									            });
											}
										});
									}
								});
					  		}}
						]
					})
	            },{
					id:'buttom',
					region : 'south',
					height : 20,
					border : false,
					
					items : [{
						xtype: 'statusbar',
				      //  statusAlign: 'left',
						items: [                    
							statusText,
							'-',
							clock
						],
						listeners: {
							render: {
								fn: function(){
									Ext.TaskManager.start({
										run: function(){
											Ext.fly(clock.getEl()).update(Ext.Date.format(new Date(), 'g:i:s A'));
										},
										interval: 1000
									});
								}
							}
						}
					}]
	            }]
	    	});
			
		});		
		
		function initTabpanel(id,text,url){
			if("" == url){
				return;
			}
			var tabs = Ext.getCmp('tabPanel');
			if (tabs) {
				var n = tabs.getComponent(id);
				//判断是否已经打开该面板
				if (!n) {   
					n = tabs.add({
						'id': id,
						'title': text,
						closable:true,
						layout: 'fit',
						border:false,
						html: '<iframe id="'+id+'" src="'+url+'" style="height:100%;width:100%;" frameborder="0"></iframe>'
					});
				}
			    tabs.setActiveTab(n);
			}
		}
		</script>
	</head>
	<body>
	<div id="div_img"><img src="${pageContext.request.contextPath}/scripts/images/bar.jpg"/></div>	
	</body>
</html>
